package com.zj.springcloud.service;

import com.zj.springcloud.pojo.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

//降级工厂
@Component
public class DeptClientServiceFailBackFactory implements FallbackFactory {
    /**
     * 失败自己回调
     * @param throwable
     * @return
     */
    @Override
    public DeptClientService create(Throwable throwable) {

        return new DeptClientService() {
            @Override
            public Dept queryById(Long id) {
                return new Dept()
                        .setDeptno(id)
                        .setDname("id=>"+id+",没有对应的信息,客户端提供了降级，服务已被关闭")
                        .setDb_source("没有数据~");
            }

            @Override
            public List<Dept> queryAll() {
                return null;
            }

            @Override
            public boolean addDept(Dept dept) {
                return false;
            }
        };
    }
}
